﻿package ascript.components.general
{
	//#########################
	// Header Includes
	//#########################
	import ascript.Game;
	import ascript.utilities.PointSimple;
	import ascript.GameComponent;
	import ascript.GameLevel;
	import ascript.GameObject;
	import Box2D.Common.Math.b2Vec2;
	
	//#########################
	// GeneralModifiers Class
	//#########################
	public class GeneralModifier extends GameComponent
	{
		//=========================
		// Constructors
		//=========================	
		public function GeneralModifier():void
		{
		}
		
		//=========================
		// Members
		//=========================
		override public function initComponent( tGame:Game, tObject:GameObject ):void
		{
			// Set Default Attributes
			defaultAttribute( tObject, "Location", new b2Vec2( tObject.x, tObject.y ) );
			defaultAttribute( tObject, "LocationInitial", new b2Vec2( tObject.x, tObject.y ) );
			defaultAttribute( tObject, "Dimensions", new PointSimple( tObject.width, tObject.height ) );
			defaultAttribute( tObject, "Pivot", new PointSimple( tObject.pivotX, tObject.pivotY ) );
			defaultAttribute( tObject, "Scale", new PointSimple( tObject.scaleX, tObject.scaleY ) );
			defaultAttribute( tObject, "Rotation", tObject.rotation );
		}
		
		override public function applyAttribute( tGame:Game, tObject:GameObject, tAttribute:String ):void
		{
			if ( tObject.getAttribute( tAttribute ) == null )
			{
				return;
			}
			
			switch( tAttribute )
			{
				case "LocationInitial":
					var tempVector:b2Vec2 = ( tObject.getAttribute( "Location" ) ).Copy();
					tempVector.Add( tObject.getAttribute( "LocationInitial" ) );
					tObject.setAttribute( "Location", tempVector );
					break;
				case "Location":
					tObject.x = ( tObject.getAttribute( "Location" ) ).x;
					tObject.y = ( tObject.getAttribute( "Location" ) ).y;
					break;
				case "Dimensions":
					tObject.width = ( tObject.getAttribute( "Dimensions" ) ).x;
					tObject.height = ( tObject.getAttribute( "Dimensions" ) ).y;
					break;
				case "Pivot":
					tObject.pivotX = ( tObject.getAttribute( "Pivot" ) ).x;
					tObject.pivotY = ( tObject.getAttribute( "Pivot" ) ).y;
					break;
				case "Scale":
					tObject.scaleX = ( tObject.getAttribute( "Scale" ) ).x;
					tObject.scaleY = ( tObject.getAttribute( "Scale" ) ).y;
					break;
				case "Rotation":
					tObject.rotation = tObject.getAttribute( "Rotation" );
					break;
				default:
					break;
			}
		}
	}
}